package com.primeton.container;

import com.sun.management.OperatingSystemMXBean;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.lang.management.ManagementFactory;
import java.util.Arrays;

@SpringBootApplication
public class ObservableApplication {

    public static void main(String[] args) {
        System.out.printf("JAVA版本号：%s；",System.getProperty("java.version"));
        System.out.println();
        Runtime rt = Runtime.getRuntime();
        long vmFree = 0;
        long vmUse = 0;
        long vmTotal = 0;
        long vmMax = 0;
        int byteToMb = 1024 * 1024;
        vmTotal = rt.totalMemory() / byteToMb;
        vmFree = rt.freeMemory() / byteToMb;
        vmMax = rt.maxMemory() / byteToMb;
        vmUse = vmTotal - vmFree;
        System.out.printf("JVM内存已用的空间为：%dM；",vmUse);
        System.out.printf("JVM内存的空闲空间为：%dM；",vmFree);
        System.out.printf("JVM总内存空间为：%dM；",vmTotal);
        System.out.printf("JVM总内存空间为：%dM；",vmMax);
        System.out.println();
        OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        long physicalFree = osmxb.getFreePhysicalMemorySize() / byteToMb;
        long physicalTotal = osmxb.getTotalPhysicalMemorySize() / byteToMb;
        long physicalUse = physicalTotal - physicalFree;
        System.out.printf("操作系统物理内存已用的空间为：%dM；",physicalFree);
        System.out.printf("操作系统物理内存的空闲空间为：%dM；",physicalUse);
        System.out.printf("操作系统总物理内存：%dM；",physicalTotal);
        System.out.println();
        System.getenv().forEach((k,v) -> {
            System.out.printf("环境变量key：%s；value：%s；",k,v);
            System.out.println();
        });
        Arrays.stream(args).forEach(item -> {
            System.out.printf("启动参数：%s；",item);
            System.out.println();
        });
        SpringApplication.run(ObservableApplication.class, args);
    }

}
